// MainDlg.h : interface of the CMainDlg class
//
/////////////////////////////////////////////////////////////////////////////

#pragma once

enum
{
    Encode_Unknown = -1, // -1 if no radio controls are checked.  
    Encode_ANSI,         // 0-based index of the radio control.
    Encode_UTF8,
    Encode_UTF16LE,
    Encode_UTF16BE
};

enum
{
    Operation_Encode = 1,
    Operation_Decode
};

class CBase64XXDlg : public CDialogImpl<CBase64XXDlg>,
                     public CWinDataExchange<CBase64XXDlg>,
                     public CMessageFilter
{
private:
    int m_nEncoding;
    int m_LastOperation;

    CEdit m_edtPlainText;
    CEdit m_edtBase64Text;
    CDropEdit m_edtFilePath;

    CButton m_rdoANSI;
    CButton m_rdoUTF8;
    CButton m_rdoUtf16LE;
    CButton m_rdoUTF16BE;

    CButton m_chkHexView;
    CButton m_chkEnableFile;
    CButton m_chkNoPadding;
    CButton m_chkNoCRLF;

    CButton m_btnBrowse;
    CButton m_btnEncode;
    CButton m_btnDecode;
    CButton m_btnDocedeToFile;

public:
	enum { IDD = IDD_MAINDLG };

    virtual BOOL PreTranslateMessage(MSG* pMsg);

	BEGIN_MSG_MAP(CBase64XXDlg)
		MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
		COMMAND_ID_HANDLER(IDOK, OnOK)
		COMMAND_ID_HANDLER(IDCANCEL, OnCancel)
        COMMAND_HANDLER(IDC_EDIT_PLAIN,         EN_CHANGE,  OnEnChangeEditPlain)
        COMMAND_HANDLER(IDC_EDIT_BASE64,        EN_CHANGE,  OnEnChangeEditBase64)
        COMMAND_HANDLER(IDC_RADIO_ANSI,         BN_CLICKED, OnBnClickedRadioCharEncoding)
        COMMAND_HANDLER(IDC_RADIO_UTF8,         BN_CLICKED, OnBnClickedRadioCharEncoding)
        COMMAND_HANDLER(IDC_RADIO_UTF16LE,      BN_CLICKED, OnBnClickedRadioCharEncoding)
        COMMAND_HANDLER(IDC_RADIO_UTF16BE,      BN_CLICKED, OnBnClickedRadioCharEncoding)
        COMMAND_HANDLER(IDC_CHECK_HEX,          BN_CLICKED, OnBnClickedCheckHexView)
        COMMAND_HANDLER(IDC_CHECK_ENABLE_FILE,  BN_CLICKED, OnBnClickedCheckEnableFile)
        COMMAND_HANDLER(IDC_CHECK_NOPAD,        BN_CLICKED, OnBnClickedCheckNoPadding)
        COMMAND_HANDLER(IDC_CHECK_NOCRLF,       BN_CLICKED, OnBnClickedCheckNoCRLF)
        COMMAND_HANDLER(IDC_BTN_BROWSE,         BN_CLICKED, OnBnClickedButtonBrowse)
        COMMAND_HANDLER(IDC_BTN_ENCODE,         BN_CLICKED, OnBnClickedButtonEncode)
        COMMAND_HANDLER(IDC_BTN_DECODE,         BN_CLICKED, OnBnClickedButtonDecode)
        COMMAND_HANDLER(IDC_BTN_DECODE_TO_FILE, BN_CLICKED, OnBnClickedButtonDecodeToFile)
    END_MSG_MAP()

    BEGIN_DDX_MAP(CBase64XXDlg)
        DDX_RADIO(IDC_RADIO_ANSI, m_nEncoding)  // The resource ID of the first radio control in the group.
        DDX_CONTROL_HANDLE(IDC_EDIT_PLAIN, m_edtPlainText)
        DDX_CONTROL_HANDLE(IDC_EDIT_BASE64, m_edtBase64Text)
        DDX_CONTROL_HANDLE(IDC_FILE_PATH, m_edtFilePath)
        DDX_CONTROL_HANDLE(IDC_RADIO_ANSI, m_rdoANSI)
        DDX_CONTROL_HANDLE(IDC_RADIO_UTF8, m_rdoUTF8)
        DDX_CONTROL_HANDLE(IDC_RADIO_UTF16LE, m_rdoUtf16LE)
        DDX_CONTROL_HANDLE(IDC_RADIO_UTF16BE, m_rdoUTF16BE)
        DDX_CONTROL_HANDLE(IDC_CHECK_HEX, m_chkHexView)
        DDX_CONTROL_HANDLE(IDC_CHECK_ENABLE_FILE, m_chkEnableFile)
        DDX_CONTROL_HANDLE(IDC_CHECK_NOPAD, m_chkNoPadding)
        DDX_CONTROL_HANDLE(IDC_CHECK_NOCRLF, m_chkNoCRLF)
        DDX_CONTROL_HANDLE(IDC_BTN_BROWSE, m_btnBrowse)
        DDX_CONTROL_HANDLE(IDC_BTN_ENCODE, m_btnEncode)
        DDX_CONTROL_HANDLE(IDC_BTN_DECODE, m_btnDecode)
        DDX_CONTROL_HANDLE(IDC_BTN_DECODE_TO_FILE, m_btnDocedeToFile)
    END_DDX_MAP()

    CBase64XXDlg();
    ~CBase64XXDlg();

// Handler prototypes (uncomment arguments if needed):
//	LRESULT MessageHandler(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
//	LRESULT CommandHandler(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
//	LRESULT NotifyHandler(int /*idCtrl*/, LPNMHDR /*pnmh*/, BOOL& /*bHandled*/)

	LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
    LRESULT OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
	LRESULT OnOK(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
	LRESULT OnCancel(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
    void CloseDialog(int nVal);

    LRESULT OnEnChangeEditPlain(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
    LRESULT OnEnChangeEditBase64(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
    LRESULT OnBnClickedRadioCharEncoding(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
    LRESULT OnBnClickedCheckHexView(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
    LRESULT OnBnClickedCheckEnableFile(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
    LRESULT OnBnClickedCheckNoPadding(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
    LRESULT OnBnClickedCheckNoCRLF(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
    LRESULT OnBnClickedButtonBrowse(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
    LRESULT OnBnClickedButtonEncode(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
    LRESULT OnBnClickedButtonDecode(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
    LRESULT OnBnClickedButtonDecodeToFile(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);

    HRESULT Base64EncodeText(const WCHAR* wszText, DWORD dwEncoding, CHAR** ppszBase64Str, DWORD dwFlags);
    HRESULT Base64DecodeToText(const WCHAR* wszBase64Text, DWORD dwEncoding, WCHAR** ppwszText);
    HRESULT Base64DecodeToHexViewText(const WCHAR* wszBase64Text, WCHAR** ppwszHexViewText);

    HRESULT Base64EncodeFile(HANDLE hSrc, HANDLE hDest, DWORD dwFlags);
    HRESULT Base64DecodeFile(HANDLE hSrc, HANDLE hDest);
};

